package com.yiwei.jmx.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.UserChannelAuthModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyQuataAdapter extends ItemAdapter<UserChannelAuthModel.DataBean.ChannelsBean, MyQuataAdapter.DefaultHolder> {


    public MyQuataAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_quata, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        UserChannelAuthModel.DataBean.ChannelsBean item = getItem(position);
        holder.txtTitle.setText(item.name);
        holder.txtCanBorrow.setText(item.last_money);
        holder.txtQuata.setText("总额度" + item.money + "元 | 已用额度" + item.use_money + "元");
        if (item.has_deal.equals("1")) {
            holder.btnSubmit.setShapeSolidColor(0xffBBC6D3).setUseShape();
        } else {
            holder.btnSubmit.setShapeSolidColor(0xff0072FF).setUseShape();
        }
        holder.btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.has_deal.equals("0")) {
                    if (onChooseListener != null) {
                        onChooseListener.onSuccess(item);
                    }
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_can_borrow)
        TextView txtCanBorrow;
        @BindView(R.id.txt_quata)
        TextView txtQuata;
        @BindView(R.id.btn_submit)
        SuperButton btnSubmit;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess(UserChannelAuthModel.DataBean.ChannelsBean item);
    }
}
